home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / HyperCuber Source / HyperCuber 2.0 Source.sit / HyperCuber 2.0 Source / Clipping.cp < prev    next >
Text File  |  1994-04-27  |  19KB  |  777 lines

  1. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. //| This file contains clipping algorithms
  3. //|________________________________________________________________________________
  4.  
  5.  
  6.  
  7. //=============================== Prototypes ===============================\\
  8.  
  9. Boolean clip_line(long *p1h, long *p1v, long *p2h, long *p2v, Rect *clip_rect);
  10.  
  11. long intersect_vert(long start_h, long start_v, long end_h, long end_v, long line_h);
  12. long intersect_horiz(long start_h, long start_v, long end_h, long end_v, long line_v);
  13. Boolean left_side(long start_h, long start_v, long end_h, long end_v,
  14.                     long point_h, long point_v);
  15.  
  16.  
  17. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. //| Procedure left_side
  19. //|
  20. //| Purpose: Find which side of a ray a point is on
  21. //|
  22. //| Parameters: point: point to classify
  23. //|             ray_start: start point of ray
  24. //|             ray_end:   endpoint of ray
  25. //|             returns TRUE if point is on the left, looking from ray_start to ray_end
  26. //|_____________________________________________________________________________________
  27.  
  28. Boolean left_side(long start_h, long start_v, long end_h, long end_v,
  29.                     long point_h, long point_v)
  30. {
  31.  
  32.     long dot_product = (end_v - start_v) * (point_h - start_h) +
  33.                         (start_h - end_h) * (point_v - start_v);
  34.  
  35.     return (dot_product < 0);
  36.  
  37. }    //==== left_side() ====\\
  38.  
  39.  
  40.  
  41. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  42. //| Procedure intersect_horiz
  43. //|
  44. //| Purpose: Find intersection of a line segment and a horizontal line
  45. //|
  46. //| Parameters: seg_start: start of line segment
  47. //|             seg_end:   end of line segment
  48. //|             line_v:    vertical coordinate of line
  49. //|             returns:   horizontal coordinate of intersection
  50. //|_____________________________________________________________________________________
  51.  
  52. long intersect_horiz(long start_h, long start_v, long end_h, long end_v, long line_v)
  53. {
  54.  
  55.     return (start_h +
  56.                 (line_v - start_v)*(end_h - start_h) /
  57.                     (end_v - start_v));
  58.  
  59. }    //==== intersect_horiz() ====\\
  60.  
  61.  
  62.  
  63. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  64. //| Procedure intersect_vert
  65. //|
  66. //| Purpose: Find intersection of a line segment and a vertical line, using
  67. //|          Nicholl-Lee-Nicholl algorithm.
  68. //|
  69. //| Parameters: seg_start: start of line segment
  70. //|             seg_end:   end of line segment
  71. //|             line_v:    horizontal coordinate of line
  72. //|             returns:   vertical coordinate of intersection
  73. //|_____________________________________________________________________________________
  74.  
  75. long intersect_vert(long start_h, long start_v, long end_h, long end_v, long line_h)
  76. {
  77.  
  78.     return (start_v +
  79.                 (line_h - start_h)*(end_v - start_v) /
  80.                     (end_h - start_h));
  81.  
  82. }    //==== intersect_vert() ====\\
  83.  
  84.  
  85.  
  86. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  87. //| Procedure clip_line
  88. //|
  89. //| Purpose: Clip a line segment to a rectangle
  90. //|
  91. //| Parameters: start:     start of line segment; received start of clipped segment
  92. //|             end:       end of line segment; received end of clipped segment
  93. //|             clip_rect: rectangle to clip to
  94. //|             returns TRUE if line was partly inside rect, FALSE if entirely outside
  95. //|_____________________________________________________________________________________
  96.  
  97. Boolean clip_line(long *p1h, long *p1v, long *p2h, long *p2v, Rect *clip_rect)
  98. {
  99.  
  100.     register long h1 = *p1h;
  101.     register long v1 = *p1v;
  102.     register long h2 = *p2h;
  103.     register long v2 = *p2v;
  104.     register short left = clip_rect->left;
  105.     register short right = clip_rect->right;
  106.     register short top = clip_rect->bottom;
  107.     register short bottom = clip_rect->top;
  108.     
  109.     if (h1 > right)
  110.         {                                                        //  p1 is right of clip
  111.         if (h2 > right)
  112.             return FALSE;                                        //  both points are right of clip
  113.             
  114.         if (v1 > top)
  115.             {                                                    //  p1 is in NE section
  116.             
  117.             if (v2 > top)
  118.                 return FALSE;                                    //  both points are above clip
  119.             
  120.             if (left_side(h1, v1, right, bottom, h2, v2))        //  both points outside clip
  121.                 return FALSE;
  122.             
  123.             if (left_side(left, top, h1, v1, h2, v2))            //  both points outside clip
  124.                 return FALSE;
  125.             
  126.             if (left_side(right, top, left, bottom, h1, v1))
  127.                 {                                                //  p1 is in lower right of NE
  128.                 if (left_side(h1, v1, left, bottom, h2, v2))
  129.                     {
  130.                     if (v2 < bottom)                            //  If p2 is outside clip, clip it
  131.                         {
  132.                         *p2v = bottom;
  133.                         *p2h = intersect_horiz(h1, v1, h2, v2, bottom);
  134.                         }
  135.                     
  136.                     *p1v = intersect_vert(h1, v1, h2, v2, right);
  137.                     *p1h = right;
  138.                     }
  139.  
  140.                 else if (left_side(h1, v1, right, top, h2, v2))
  141.                     {
  142.                     if (h2 < left)                                //  If p2 is outside clip, clip it
  143.                         {
  144.                         *p2h = left;
  145.                         *p2v = intersect_vert(h1, v1, h2, v2, left);
  146.                         }
  147.                     
  148.                     *p1v = intersect_vert(h1, v1, h2, v2, right);
  149.                     *p1h = right;
  150.                     }
  151.  
  152.                 else
  153.                     {
  154.                     if (h2 < left)                                //  If p2 is outside clip, clip it
  155.                         {
  156.                         *p2h = left;
  157.                         *p2v = intersect_vert(h1, v1, h2, v2, left);
  158.                         }
  159.                     
  160.                     *p1h = intersect_horiz(h1, v1, h2, v2, top);
  161.                     *p1v = top;
  162.                     }
  163.                 
  164.                 }
  165.             else
  166.                 {                                                //  p1 is in upper left of NE
  167.                 if (left_side(h1, v1, right, top, h2, v2))
  168.                     {
  169.                     if (v2 < bottom)                            //  If p2 is outside clip, clip it
  170.                         {
  171.                         *p2v = bottom;
  172.                         *p2h = intersect_horiz(h1, v1, h2, v2, bottom);
  173.                         }
  174.                     
  175.                     *p1v = intersect_vert(h1, v1, h2, v2, right);
  176.                     *p1h = right;
  177.                     }
  178.  
  179.                 else if (left_side(h1, v1, left, bottom, h2, v2))
  180.                     {
  181.                     if (v2 < bottom)                            //  If p2 is outside clip, clip it
  182.                         {
  183.                         *p2v = bottom;
  184.                         *p2h = intersect_horiz(h1, v1, h2, v2, bottom);
  185.                         }
  186.                     
  187.                     *p1h = intersect_horiz(h1, v1, h2, v2, top);
  188.                     *p1v = top;
  189.                     }
  190.  
  191.  
  192.                 else
  193.                     {
  194.                     if (h2 < left)                                //  If p2 is outside clip, clip it
  195.                         {
  196.                         *p2h = left;
  197.                         *p2v = intersect_vert(h1, v1, h2, v2, left);
  198.                         }
  199.                     
  200.                     *p1h = intersect_horiz(h1, v1, h2, v2, top);
  201.                     *p1v = top;
  202.                     }
  203.                 
  204.                 }
  205.             }
  206.                     
  207.         else if (v1 < bottom)
  208.             {                                                    //  p1 is in SE section
  209.             
  210.             if (v2 < bottom)
  211.                 return FALSE;                                    //  both points are below clip
  212.             
  213.             if (left_side(right, top, h1, v1, h2, v2))            //  both points outside clip
  214.                 return FALSE;
  215.             
  216.             if (left_side(h1, v1, left, bottom, h2, v2))        //  both points outside clip
  217.                 return FALSE;
  218.             
  219.             if (left_side(right, bottom, left, top, h1, v1))
  220.                 {                                                //  p1 is in lower left of SE
  221.                 if (left_side(h1, v1, left, top, h2, v2))
  222.                     {
  223.                     if (h2 < left)                                //  If p2 is outside clip, clip it
  224.                         {
  225.                         *p2h = left;
  226.                         *p2v = intersect_vert(h1, v1, h2, v2, left);
  227.                         }
  228.                     
  229.                     *p1h = intersect_horiz(h1, v1, h2, v2, bottom);
  230.                     *p1v = bottom;
  231.                     }
  232.  
  233.                 else if (left_side(h1, v1, right, bottom, h2, v2))
  234.                     {
  235.                     if (v2 > top)                                //  If p2 is outside clip, clip it
  236.                         {
  237.                         *p2h = intersect_horiz(h1, v1, h2, v2, top);
  238.                         *p2v = top;
  239.                         }
  240.                     
  241.                     *p1h = intersect_horiz(h1, v1, h2, v2, bottom);
  242.                     *p1v = bottom;
  243.                     }
  244.  
  245.                 else
  246.                     {
  247.                     if (v2 > top)                                //  If p2 is outside clip, clip it
  248.                         {
  249.                         *p2h = intersect_horiz(h1, v1, h2, v2, top);
  250.                         *p2v = top;
  251.                         }
  252.                     
  253.                     *p1v = intersect_vert(h1, v1, h2, v2, right);
  254.                     *p1h = right;
  255.                     }
  256.                 
  257.                 }
  258.             else
  259.                 {                                                //  p1 is in upper right of SE
  260.                 if (left_side(h1, v1, right, bottom, h2, v2))
  261.                     {
  262.                     if (h2 < left)                                //  If p2 is outside clip, clip it
  263.                         {
  264.                         *p2h = left;
  265.                         *p2v = intersect_vert(h1, v1, h2, v2, left);
  266.                         }
  267.                     
  268.                     *p1h = intersect_horiz(h1, v1, h2, v2, bottom);
  269.                     *p1v = bottom;
  270.                     }
  271.  
  272.                 else if (left_side(h1, v1, left, top, h2, v2))
  273.                     {
  274.                     if (h2 < left)                                //  If p2 is outside clip, clip it
  275.                         {
  276.                         *p2h = left;
  277.                         *p2v = intersect_vert(h1, v1, h2, v2, left);
  278.                         }
  279.                     
  280.                     *p1v = intersect_vert(h1, v1, h2, v2, right);
  281.                     *p1h = right;
  282.                     }
  283.  
  284.  
  285.                 else
  286.                     {
  287.                     if (v2 > top)                                //  If p2 is outside clip, clip it
  288.                         {
  289.                         *p2h = intersect_horiz(h1, v1, h2, v2, top);
  290.                         *p2v = top;
  291.                         }
  292.                                         
  293.                     *p1v = intersect_vert(h1, v1, h2, v2, right);
  294.                     *p1h = right;
  295.                     }
  296.                 
  297.                 }
  298.             }
  299.                     
  300.         else
  301.             {                                                    //  p1 is in E section
  302.             
  303.             if (left_side(right, top, h1, v1, h2, v2))            //  both points outside clip
  304.                 return FALSE;
  305.             
  306.             if (left_side(h1, v1, right, bottom, h2, v2))        //  both points outside clip
  307.                 return FALSE;
  308.             
  309.             if (left_side(left, top, h1, v1, h2, v2))
  310.                 {
  311.                 if (v2 > top)                                    //  If p2 is outside clip, clip it
  312.                     {
  313.                     *p2h = intersect_horiz(h1, v1, h2, v2, top);
  314.                     *p2v = top;
  315.                     }
  316.                 }
  317.                 
  318.             else if (left_side(h1, v1, left, bottom, h2, v2))
  319.                 {
  320.                 if (v2 < bottom)                                //  If p2 is outside clip, clip it
  321.                     {
  322.                     *p2h = intersect_horiz(h1, v1, h2, v2, bottom);
  323.                     *p2v = bottom;
  324.                     }
  325.                 }
  326.                 
  327.             else
  328.                 {
  329.                 if (h2 < left)                                    //  If p2 is outside clip, clip it
  330.                     {
  331.                     *p2v = intersect_vert(h1, v1, h2, v2, left);
  332.                     *p2h = left;
  333.                     }
  334.                 }
  335.         
  336.             *p1v = intersect_vert(h1, v1, h2, v2, right);
  337.             *p1h = right;
  338.             }
  339.         }
  340.  
  341.     else if (h1 < left)
  342.         {                                                        //  p1 is left of clip
  343.         if (h2 < left)
  344.             return FALSE;                                        //  both points are left of clip
  345.             
  346.         if (v1 > top)
  347.             {                                                    //  p1 is in NW section
  348.             
  349.             if (v2 > top)
  350.                 return FALSE;                                    //  both points are above clip
  351.             
  352.             if (left_side(left, bottom, h1, v1, h2, v2))        //  both points outside clip
  353.                 return FALSE;
  354.             
  355.             if (left_side(h1, v1, right, top, h2, v2))            //  both points outside clip
  356.                 return FALSE;
  357.             
  358.             if (left_side(left, top, right, bottom, h1, v1))
  359.                 {                                                //  p1 is in upper right of NW
  360.                 if (left_side(h1, v1, right, bottom, h2, v2))
  361.                     {
  362.                     if (h2 > right)                                //  If p2 is outside clip, clip it
  363.                         {
  364.                         *p2h = right;
  365.                         *p2v = intersect_vert(h1, v1, h2, v2, right);
  366.                         }
  367.                     
  368.                     *p1h = intersect_horiz(h1, v1, h2, v2, top);
  369.                     *p1v = top;
  370.                     }
  371.  
  372.                 else if (left_side(h1, v1, left, top, h2, v2))
  373.                     {
  374.                     if (v2 < bottom)                            //  If p2 is outside clip, clip it
  375.                         {
  376.                         *p2h = intersect_horiz(h1, v1, h2, v2, bottom);
  377.                         *p2v = bottom;
  378.                         }
  379.                     
  380.                     *p1h = intersect_horiz(h1, v1, h2, v2, top);
  381.                     *p1v = top;
  382.                     }
  383.  
  384.                 else
  385.                     {
  386.                     if (v2 < bottom)                            //  If p2 is outside clip, clip it
  387.                         {
  388.                         *p2h = intersect_horiz(h1, v1, h2, v2, bottom);
  389.                         *p2v = bottom;
  390.                         }
  391.                     
  392.                     *p1v = intersect_vert(h1, v1, h2, v2, left);
  393.                     *p1h = left;
  394.                     }
  395.                 
  396.                 }
  397.             else
  398.                 {                                                //  p1 is in lower left of NW
  399.                 if (left_side(h1, v1, left, top, h2, v2))
  400.                     {
  401.                     if (h2 > right)                                //  If p2 is outside clip, clip it
  402.                         {
  403.                         *p2h = right;
  404.                         *p2v = intersect_vert(h1, v1, h2, v2, right);
  405.                         }
  406.                     
  407.                     *p1h = intersect_horiz(h1, v1, h2, v2, top);
  408.                     *p1v = top;
  409.                     }
  410.  
  411.                 else if (left_side(h1, v1, right, bottom, h2, v2))
  412.                     {
  413.                     if (h2 > right)                                //  If p2 is outside clip, clip it
  414.                         {
  415.                         *p2h = right;
  416.                         *p2v = intersect_vert(h1, v1, h2, v2, right);
  417.                         }
  418.                     
  419.                     *p1v = intersect_vert(h1, v1, h2, v2, left);
  420.                     *p1h = left;
  421.                     }
  422.  
  423.  
  424.                 else
  425.                     {
  426.                     if (v2 < bottom)                            //  If p2 is outside clip, clip it
  427.                         {
  428.                         *p2h = intersect_horiz(h1, v1, h2, v2, bottom);
  429.                         *p2v = bottom;
  430.                         }
  431.                                         
  432.                     *p1v = intersect_vert(h1, v1, h2, v2, left);
  433.                     *p1h = left;
  434.                     }
  435.                 
  436.                 }
  437.             }
  438.                     
  439.         else if (v1 < bottom)
  440.             {                                                    //  p1 is in SW section
  441.             
  442.             if (v2 < bottom)
  443.                 return FALSE;                                    //  both points are below clip
  444.             
  445.             if (left_side(right, bottom, h1, v1, h2, v2))        //  both points outside clip
  446.                 return FALSE;
  447.             
  448.             if (left_side(h1, v1, left, top, h2, v2))            //  both points outside clip
  449.                 return FALSE;
  450.             
  451.             if (left_side(left, bottom, right, top, h1, v1))
  452.                 {                                                //  p1 is in upper left of SW
  453.                 if (left_side(h1, v1, right, top, h2, v2))
  454.                     {
  455.                     if (v2 > top)                                //  If p2 is outside clip, clip it
  456.                         {
  457.                         *p2h = intersect_horiz(h1, v1, h2, v2, top);
  458.                         *p2v = top;
  459.                     }
  460.                     
  461.                     *p1v = intersect_vert(h1, v1, h2, v2, left);
  462.                     *p1h = left;
  463.                     }
  464.  
  465.                 else if (left_side(h1, v1, left, bottom, h2, v2))
  466.                     {
  467.                     if (h2 > right)                                //  If p2 is outside clip, clip it
  468.                         {
  469.                         *p2h = right;
  470.                         *p2v = intersect_vert(h1, v1, h2, v2, right);
  471.                         }
  472.                     
  473.                     *p1v = intersect_vert(h1, v1, h2, v2, left);
  474.                     *p1h = left;
  475.                     }
  476.  
  477.                 else
  478.                     {
  479.                     if (h2 > right)                                //  If p2 is outside clip, clip it
  480.                         {
  481.                         *p2h = right;
  482.                         *p2v = intersect_vert(h1, v1, h2, v2, right);
  483.                         }
  484.                     
  485.                     *p1h = intersect_horiz(h1, v1, h2, v2, bottom);
  486.                     *p1v = bottom;
  487.                     }
  488.                 
  489.                 }
  490.             else
  491.                 {                                                //  p1 is in lower right of SW
  492.                 if (left_side(h1, v1, left, bottom, h2, v2))
  493.                     {
  494.                     if (v2 > top)                                //  If p2 is outside clip, clip it
  495.                         {
  496.                         *p2h = intersect_horiz(h1, v1, h2, v2, top);
  497.                         *p2v = top;
  498.                         }
  499.                     
  500.                     *p1v = intersect_vert(h1, v1, h2, v2, left);
  501.                     *p1h = left;
  502.                     }
  503.  
  504.                 else if (left_side(h1, v1, right, top, h2, v2))
  505.                     {
  506.                     if (v2 > top)                                //  If p2 is outside clip, clip it
  507.                         {
  508.                         *p2h = intersect_horiz(h1, v1, h2, v2, top);
  509.                         *p2v = top;
  510.                         }
  511.                     
  512.                     *p1h = intersect_horiz(h1, v1, h2, v2, bottom);
  513.                     *p1v = bottom;
  514.                     }
  515.  
  516.  
  517.                 else
  518.                     {
  519.                     if (h2 > right)                                //  If p2 is outside clip, clip it
  520.                         {
  521.                         *p2v = intersect_vert(h1, v1, h2, v2, right);
  522.                         *p2h = right;
  523.                         }
  524.                                         
  525.                     *p1h = intersect_horiz(h1, v1, h2, v2, bottom);
  526.                     *p1v = bottom;
  527.                     }
  528.                 
  529.                 }
  530.             }
  531.         
  532.         else
  533.             {                                                    //  p1 is in W section
  534.             
  535.             if (left_side(left, bottom, h1, v1, h2, v2))        //  both points outside clip
  536.                 return FALSE;
  537.             
  538.             if (left_side(h1, v1, left, top, h2, v2))            //  both points outside clip
  539.                 return FALSE;
  540.             
  541.             if (left_side(h1, v1, right, top, h2, v2))
  542.                 {
  543.                 if (v2 > top)                                    //  If p2 is outside clip, clip it
  544.                     {
  545.                     *p2h = intersect_horiz(h1, v1, h2, v2, top);
  546.                     *p2v = top;
  547.                     }
  548.                 }
  549.  
  550.             else if (left_side(right, bottom, h1, v1, h2, v2))
  551.                 {
  552.                 if (v2 < bottom)                                //  If p2 is outside clip, clip it
  553.                     {
  554.                     *p2h = intersect_horiz(h1, v1, h2, v2, bottom);
  555.                     *p2v = bottom;
  556.                     }
  557.                 }
  558.  
  559.             else
  560.                 {
  561.                 if (h2 > right)                                    //  If p2 is outside clip, clip it
  562.                     {
  563.                     *p2v = intersect_vert(h1, v1, h2, v2, right);
  564.                     *p2h = right;
  565.                     }
  566.                 }
  567.                 
  568.             *p1v = intersect_vert(h1, v1, h2, v2, left);
  569.             *p1h = left;
  570.             }
  571.         
  572.         }
  573.  
  574.     else
  575.         {                                                        //  Point is horizontally in clip
  576.         
  577.         if (v1 > top)
  578.             {                                                    //  Point is in N section
  579.             
  580.             if (v2 > top)                                        //  both points above clip
  581.                 return (FALSE);
  582.             
  583.             if (left_side(h1, v1, right, top, h2, v2))
  584.                 return (FALSE);                                    //  both points outside clip
  585.             
  586.             if (left_side(left, top, h1, v1, h2, v2))
  587.                 return (FALSE);                                    //  both points outside clip
  588.             
  589.             if (left_side(h1, v1, right, bottom, h2, v2))
  590.                 {
  591.                 if (h2 > right)                                    //  If p2 is outside clip, clip it
  592.                     {
  593.                     *p2v = intersect_vert(h1, v1, h2, v2, right);
  594.                     *p2h = right;
  595.                     }
  596.                 }
  597.         
  598.             else if (left_side(left, bottom, h1, v1, h2, v2))
  599.                 {
  600.                 if (h2 < left)                                    //  If p2 is outside clip, clip it
  601.                     {
  602.                     *p2v = intersect_vert(h1, v1, h2, v2, left);
  603.                     *p2h = left;
  604.                     }
  605.                 }
  606.  
  607.             else
  608.                 {
  609.                 if (v2 < bottom)                                //  If p2 is outside clip, clip it
  610.                     {
  611.                     *p2h = intersect_horiz(h1, v1, h2, v2, bottom);
  612.                     *p2v = bottom;
  613.                     }
  614.                 }
  615.  
  616.             *p1h = intersect_horiz(h1, v1, h2, v2, top);
  617.             *p1v = top;
  618.             
  619.             }
  620.         
  621.         else if (v1 < bottom)
  622.             {                                                    //  Point is in S section
  623.             
  624.             if (v2 < bottom)                                    //  both points below clip
  625.                 return (FALSE);
  626.             
  627.             if (left_side(h1, v1, left, bottom, h2, v2))
  628.                 return (FALSE);                                    //  both points outside clip
  629.             
  630.             if (left_side(right, bottom, h1, v1, h2, v2))
  631.                 return (FALSE);                                    //  both points outside clip
  632.             
  633.             if (left_side(h1, v1, left, top, h2, v2))
  634.                 {
  635.                 if (h2 < left)                                    //  If p2 is outside clip, clip it
  636.                     {
  637.                     *p2v = intersect_vert(h1, v1, h2, v2, left);
  638.                     *p2h = left;
  639.                     }
  640.                 }
  641.         
  642.             else if (left_side(right, top, h1, v1, h2, v2))
  643.                 {
  644.                 if (h2 > right)                                    //  If p2 is outside clip, clip it
  645.                     {
  646.                     *p2v = intersect_vert(h1, v1, h2, v2, right);
  647.                     *p2h = right;
  648.                     }
  649.                 }
  650.  
  651.             else
  652.                 {
  653.                 if (v2 > top)                                    //  If p2 is outside clip, clip it
  654.                     {
  655.                     *p2h = intersect_horiz(h1, v1, h2, v2, top);
  656.                     *p2v = top;
  657.                     }
  658.                 }
  659.  
  660.             *p1h = intersect_horiz(h1, v1, h2, v2, bottom);
  661.             *p1v = bottom;
  662.             
  663.             }
  664.         
  665.         else
  666.             {                                                    //  Point is in clip
  667.             
  668.             if (v2 > top)
  669.                 {                                                //  Point2 is above clip
  670.                 
  671.                 if (h2 > right)
  672.                     {                                            //  Point2 is in NE section
  673.                     
  674.                     if (left_side(h1, v1, right, top, h2, v2))
  675.                         {
  676.                         *p2h = intersect_horiz(h1, v1, h2, v2, top);
  677.                         *p2v = top;
  678.                         }
  679.                     
  680.                     else
  681.                         {
  682.                         *p2v = intersect_vert(h1, v1, h2, v2, right);
  683.                         *p2h = right;
  684.                         }
  685.                     
  686.                     }
  687.  
  688.                 else if (h2 < left)
  689.                     {                                            //  Point2 is in NW section
  690.                     if (left_side(h1, v1, left, top, h2, v2))
  691.                         {
  692.                         *p2v = intersect_vert(h1, v1, h2, v2, left);
  693.                         *p2h = left;
  694.                         }
  695.                     
  696.                     else
  697.                         {
  698.                         *p2h = intersect_horiz(h1, v1, h2, v2, top);
  699.                         *p2v = top;
  700.                         }
  701.                     
  702.                     }
  703.  
  704.                 else                                            //  Point2 is in N section
  705.                     {
  706.                     *p2h = intersect_horiz(h1, v1, h2, v2, top);
  707.                     *p2v = top;
  708.                     }
  709.                 
  710.                 }
  711.                 
  712.             else if (v2 < bottom)
  713.                 {                                                //  Point2 is below clip
  714.                 if (h2 > right)
  715.                     {                                            //  Point2 is in SE section
  716.                     if (left_side(h1, v1, right, bottom, h2, v2))
  717.                         {
  718.                         *p2v = intersect_vert(h1, v1, h2, v2, right);
  719.                         *p2h = right;
  720.                         }
  721.                     
  722.                     else
  723.                         {
  724.                         *p2h = intersect_horiz(h1, v1, h2, v2, bottom);
  725.                         *p2v = bottom;
  726.                         }
  727.                     }
  728.  
  729.                 else if (h2 < left)
  730.                     {                                            //  Point2 is in SW section
  731.                     if (left_side(h1, v1, left, bottom, h2, v2))
  732.                         {
  733.                         *p2h = intersect_horiz(h1, v1, h2, v2, bottom);
  734.                         *p2v = bottom;
  735.                         }
  736.                         
  737.                     else
  738.                         {
  739.                         *p2v = intersect_vert(h1, v1, h2, v2, left);
  740.                         *p2h = left;
  741.                         }
  742.                     }
  743.                     
  744.                 else                                            //  Point2 is in N section
  745.                     {
  746.                     *p2h = intersect_horiz(h1, v1, h2, v2, bottom);
  747.                     *p2v = bottom;
  748.                     }
  749.                 
  750.                 }
  751.             else
  752.                 {                                                //  Point2 is vertically in clip
  753.                 
  754.                 if (h2 > right)
  755.                     {
  756.                     *p2v = intersect_vert(h1, v1, h2, v2, right);    //  Point2 is in E section
  757.                     *p2h = right;
  758.                     }
  759.  
  760.                 else if (h2 < left)
  761.                     {
  762.                     *p2v = intersect_vert(h1, v1, h2, v2, left);    //  Point2 is in W section
  763.                     *p2h = left;
  764.                     }
  765.  
  766.                 //  else Point2 is in clip
  767.                 
  768.                 }
  769.             
  770.             }
  771.         
  772.         }
  773.         
  774.     return TRUE;
  775.  
  776. }    //==== clip_line() ====\\
  777.